//引用express框架
const express = require('express');
//引入body_parser框架
const bodyParser = require('body-parser');
//创建网站服务器
const app = express();

//引入路由模块
const login = require('./routes/login');
const pushTask = require('./routes/pushTask');
const getTask = require('./routes/getTask');
const getStep = require('./routes/getStep');
const dropTask = require('./routes/dropTask');
const cancelTask = require('./routes/cancelTask');
const getUserInfor = require('./routes/getUserInfor');
const myJoinTask = require('./routes/myJoinTask');
const myPushTask = require('./routes/myPushTask');
const modifiyStepNum = require('./routes/modifiyStepNum');
const getCompleteInfor = require('./routes/getCompleteInfor');
const deposit = require('./routes/deposit');
const completeTask = require('./routes/completeTask');

//配置中间件
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())

app.all('*', function (req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
    // res.setHeader("Content-Type", "application/json;charset=utf-8"); 
    next();
});

//为路由匹配路径 

// 登录接口
app.use('/login', login);
// 发布任务接口
app.use('/pushTask', pushTask)
// 获取任务接口
app.use('/getTask', getTask)
// 获取步骤接口
app.use('/getStep', getStep)
// 删除任务接口
app.use('/dropTask', dropTask)
// 放弃任务接口
app.use('/cancelTask', cancelTask)
// 获取用户信息接口
app.use('/getUserInfor', getUserInfor)
// 获取我的参加
app.use('/myJoinTask', myJoinTask)
// 获取我的发布
app.use('/myPushTask', myPushTask)
// 修改完成数量
app.use('/modifiyStepNum', modifiyStepNum)
// 查看用户完成情况
app.use('/getCompleteInfor', getCompleteInfor)
// 用户充值
app.use('/deposit', deposit)
// 完成任务
app.use('/completeTask', completeTask)

//监听端口
app.listen(80);

console.log('网站服务器启动成功，请访问localhost');